import { h, ref } from 'vue';

export const columns = [
  {
    title: '用户ID',
    key: 'userId',
    width: 80,
  },
  {
    title: '角色ID',
    key: 'roleId',
    width: 110,
  },
  {
    title: 'CP订单号',
    key: 'cpOrderNo',
    width: 200,
  },
  {
    title: '道具名称',
    key: 'propsName',
    width: 100,
  },
  {
    title: '充值金额',
    key: 'amount',
    width: 70,
  },
  {
    title: '支付方式',
    key: 'payWay',
    width: 70,
    render(row) {
      return h(
        'span',
        { style: row.payWay == 'wechat' ? 'color:green' : 'color:blue' },
        {
          default: () =>
            row.payWay == 'wechat' ? '微信' : row.payWay == 'alipay' ? '支付宝' : '未知',
        }
      );
    },
  },
  {
    title: '交易状态',
    key: 'payStatus',
    width: 70,
    render(row) {
      return h(
        'span',
        { style: row.payStatus == 'success' ? 'color:green' : 'color:red' },
        {
          default: () => (row.payStatus == 'success' ? '已支付' : '未支付'),
        }
      );
    },
  },
  {
    title: '支付时间',
    key: 'createTime',
    width: 110,
  },
];

const switchAction = ref<StatusSwitchAction[]>([]);

export interface StatusSwitchAction {
  type: string;
  action: Function;
}

export function registerHandler(actions: StatusSwitchAction[]) {
  switchAction.value = actions;
}
